
;
var BASE = BASE || {};
(function($, $$) {

    function RandomString(legalCharList) {
        var defaultLegalChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        if (legalCharList === undefined) {
            this._legalCharList = defaultLegalChar.split("");
        }
        else {
            this._legalCharList = legalCharList.split("");
        }
        this.legalListLength = this._legalCharList.length;
    }

    RandomString.prototype = {

        getRandomStr : function(length) {
            if (length === undefined) {
                length = 10;
            }
            var str = "";
            for (var i = 0; i < length; i++) {
                str += this._getRandomChar();
            }
            return str;
        },
        _getRandomChar : function() {
            var index = Math.floor(Math.random() * this.legalListLength);
            return this._legalCharList[index];
        }
    };
    $.extend($$, {

        version : "0.8.1",

        msie6 : $.browser.msie && $.browser.version == "6.0",

        defaultAnimateDuration : 300,

        defaultBorder : "uiBlueBorder",

        defaultBoxShadow : "uiBlueBoxShadow",

        defaultGradientBG : "uiBlueGradientBG",

        hoverGradientBG : "uiLightBlueGradientBG",

        selectedGradientBG : "uiRedGradientBG",

        cssShow : {
            position: "absolute",
            visibility: "hidden",
            display: "block"
        },


        widgetType : {
            uiDialog : "dialog",
            uiTabs : "tabs",
            uiSlide : "slide",
            uiAccordion : "accordion",
            uiButtonSet : "buttonSet",
            uiDorpDownList : "dropDownList",
            uiProgressBar : "progressBar",
            uiTip : "tip",
            uiList : "list",
            uiDatePicker : "datePicker",
            uiTree : "tree",
            uiGrid : "grid"
        },

        widgetDictionary : {},

        randomKey : new RandomString(),

        getWidget : function(key) {
            if (this.widgetDictionary[key] !== undefined) {
                return this.widgetDictionary[key];
            }
            return null;
        },

        addWidget : function(key, widget) {
            this.widgetDictionary[key] = widget;
        },

        removeWidget : function(key) {
            if (this.widgetDictionary[key] !== undefined) {
                var widget = this.widgetDictionary[key];
                this.widgetDictionary[key] = null;
                if (! delete this.widgetDictionary[key]) {
                    this.widgetDictionary[key] = null;
                }
                var opts = widget.opts;
                for (var prop in opts) {
                    if (opts.hasOwnProperty(prop)) {
                        if (! delete opts[prop]) {
                            opts[prop] = null;
                        }
                    }
                }
                for (var prop in widget) {
                    if (widget.hasOwnProperty(prop)) {
                        if (! delete widget[prop]) {
                            widget[prop] = null;
                        }
                    }
                }
                widget = null;
            }
        },

        getRandomKey : function(length) {
            return  this.randomKey.getRandomStr(length);
        },

        inherit : function(subClass, superClass, subFunction) {
            if (!$.isFunction(subClass) || !$.isFunction(superClass)) {
                $.error("继承出错");
            }
            var temp = new superClass();
            var tempClass = function() {
            };
            tempClass.prototype = superClass.prototype;
            subClass.prototype = new tempClass();
            subClass.prototype.constructor = subClass;
            subClass.prototype.superClass = superClass;
            $.extend(subClass.prototype, subFunction);
        },

        createWidgetByJQuery : function() {
            var self = this, args = Array.prototype.slice.call(arguments), constructor = args.pop(), options = args[0], widgetObj;
            if (typeof options == "string") {
                var widgetKey = self.attr("widget");
                if (widgetKey !== undefined) {
                    widgetObj = $$.getWidget(widgetKey);
                    return widgetObj.selectHandle.apply(widgetObj, args);
                }
            }
            else {
                widgetObj = new constructor(self, options);
            }
            return self;
        }
    });
})(jQuery, BASE);
